package magicboard.model
{
  import flash.geom.Point;
  
  import flexunit.framework.TestCase;
  import flexunit.framework.TestSuite;
  
  import magicboard.geometry.LineSegment;
  
  public class LineSegmentTestCase extends TestCase
  {
    // --------------------------------------------------------------------------------------------	
    public function LineSegmentTestCase(methodName:String) {
   	 super( methodName );
    }

    // --------------------------------------------------------------------------------------------	
    public static function suite():TestSuite {
   			var ts:TestSuite = new TestSuite();
   			
   			ts.addTest( new LineSegmentTestCase( "testDistanceLineToPoint1" ) );
   			ts.addTest( new LineSegmentTestCase( "testDistanceLineToPoint2" ) );
   			ts.addTest( new LineSegmentTestCase( "testDistanceSegmentToPoint1" ) );
   			ts.addTest( new LineSegmentTestCase( "testDistanceSegmentToPoint2" ) );
   			ts.addTest( new LineSegmentTestCase( "testDistanceSegmentToPoint3" ) );
   			ts.addTest( new LineSegmentTestCase( "testDistanceSegmentToPoint4" ) );
   			ts.addTest( new LineSegmentTestCase( "testLength" ) );
   			return ts;
   		}

  
    // --------------------------------------------------------------------------------------------
		public function testDistanceLineToPoint1():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(0,0));
 			var p1:Point = new Point(2,11); 
 			var distance:Number;

      distance = line.distanceToLine(p1); 			
 			assertEquals(11, distance );
 		}
  		
    // --------------------------------------------------------------------------------------------
    // Point on the line
		public function testDistanceLineToPoint2():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(2,1));
 			var p1:Point = new Point(3, 2); 
 			var distance:Number;

      distance = line.distanceToLine(p1); 			
 			assertEquals(0, distance );
 		}
  		
    // --------------------------------------------------------------------------------------------
    // Inside segment 
		public function testDistanceSegmentToPoint1():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(0,0));
 			
 			assertEquals(0, line.distanceToSegment2(new Point(0.5,0)) );
 		}
  		
    // --------------------------------------------------------------------------------------------
    // On end of segment 
		public function testDistanceSegmentToPoint2():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(0,0));
 			
 			assertEquals(0, line.distanceToSegment2(new Point(1,0)) );
 		}
  		
    // --------------------------------------------------------------------------------------------
    // On line from segment 
		public function testDistanceSegmentToPoint3():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(0,0));
 			
 			assertEquals(16, line.distanceToSegment2(new Point(5,0)) );
 			assertEquals(25, line.distanceToSegment2(new Point(-5,0)) );
 		}
  		
    // --------------------------------------------------------------------------------------------
    // Not linear 
		public function testDistanceSegmentToPoint4():void {
 			
 			var line:LineSegment = new LineSegment(new Point(1,0), new Point(0,0));
 			
 			assertEquals(1, line.distanceToSegment2(new Point(1,1)) );
 			assertEquals(2, line.distanceToSegment2(new Point(-1,-1)) );
 		}
  		
    // --------------------------------------------------------------------------------------------
		public function testLength():void {
 			
 			var line:LineSegment = new LineSegment(new Point(0,0), new Point(4,3));

 			assertEquals(5, line.getLineLength() );
 		}
  		
 	}
}